package com.wz.project.bas.inoroutType.controller;

import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.bas.inoroutType.domain.BasInOrOutType;
import com.wz.project.bas.inoroutType.service.IBasInOrOutTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 出入库类型Controller
 * 
 * @author wz
 * @date 2022-02-11
 */
@Controller
@RequestMapping("/bas/inoroutType")
public class BasInOrOutTypeController extends BaseController
{
    private String prefix = "bas/inoroutType";

    @Autowired
    private IBasInOrOutTypeService basInOrOutTypeService;

    @RequiresPermissions("bas:inoroutType:view")
    @GetMapping()
    public String inoroutType()
    {
        return prefix + "/inoroutType";
    }

    /**
     * 查询出入库类型列表
     */
//    @RequiresPermissions("bas:inoroutType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasInOrOutType basInOrOutType)
    {
        startPage();
        List<BasInOrOutType> list = basInOrOutTypeService.selectBasInOrOutTypeList(basInOrOutType);
        return getDataTable(list);
    }

    /**
     * 导出出入库类型列表
     */
    @RequiresPermissions("bas:inoroutType:export")
    @Log(title = "出入库类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasInOrOutType basInOrOutType)
    {
        List<BasInOrOutType> list = basInOrOutTypeService.selectBasInOrOutTypeList(basInOrOutType);
        ExcelUtil<BasInOrOutType> util = new ExcelUtil<BasInOrOutType>(BasInOrOutType.class);
        return util.exportExcel(list, "inoroutType");
    }

    /**
     * 新增出入库类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存出入库类型
     */
    @RequiresPermissions("bas:inoroutType:add")
    @Log(title = "出入库类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasInOrOutType basInOrOutType)
    {
        return toAjax(basInOrOutTypeService.insertBasInOrOutType(basInOrOutType));
    }

    /**
     * 修改出入库类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BasInOrOutType basInOrOutType = basInOrOutTypeService.selectBasInOrOutTypeById(id);
        mmap.put("basInOrOutType", basInOrOutType);
        return prefix + "/edit";
    }

    /**
     * 修改保存出入库类型
     */
    @RequiresPermissions("bas:inoroutType:edit")
    @Log(title = "出入库类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasInOrOutType basInOrOutType)
    {
        return toAjax(basInOrOutTypeService.updateBasInOrOutType(basInOrOutType));
    }

    /**
     * 删除出入库类型
     */
    @RequiresPermissions("bas:inoroutType:remove")
    @Log(title = "出入库类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basInOrOutTypeService.deleteBasInOrOutTypeByIds(ids));
    }
}
